The law of specific nerve energies, first proposed by Johannes Peter Müller in 1835, is that the nature of perception is defined by the pathway over which the sensory information is carried. Hence, the origin of the sensation is not important. Therefore the differences in sensory quality, the difference between seeing and hearing, between hearing and touch, and so on - are not caused by differences in the stimuli themselves but by the different nervous structures that these stimuli excite. For example, pressing on the eye elicits sensations of flashes of light because the neurons in the retina send a signal to the occipital lobe. Despite the sensory input's being mechanical, the experience is visual.
Here is Müller's statement of the law, from Handbuch der Physiologie des Menschen für Vorlesungen, 2nd Ed., translated by Edwin Clarke and Charles Donald O'Malley:
The same cause, such as electricity, can simultaneously affect all sensory organs, since they are all sensitive to it; and yet, every sensory nerve reacts to it differently; one nerve perceives it as light, another hears its sound, another one smells it; another tastes the electricity, and another one feels it as pain and shock. One nerve perceives a luminous picture through mechanical irritation, another one hears it as buzzing, another one senses it as pain. . . He who feels compelled to consider the consequences of these facts cannot but realize that the specific sensibility of nerves for certain impressions is not enough, since all nerves are sensitive to the same cause but react to the same cause in different ways. . . (S)ensation is not the conduction of a quality or state of external bodies to consciousness, but the conduction of a quality or state of our nerves to consciousness, excited by an external cause.
As the above quotation shows, Müller's law seems to differ from the modern statement of the law in one key way. Müller attributed the quality of an experience to some specific quality of the energy in the nerves. For example, the visual experience from light shining into the eye, or from a poke in the eye, arises from some special quality of the energy carried by optic nerve, and the auditory experience from sound coming into the ear, or from electrical stimulation of the cochlea, arises from some different, special quality of the energy carried by the auditory nerve. In 1912, Lord Edgar Douglas Adrian showed that all neurons carry the same energy, electrical energy in the form of action potentials. That means that the quality of an experience depends on the part of the brain to which nerves deliver their action potentials (e.g., light from nerves arriving at the visual cortex and sound from nerves arriving at the auditory cortex).
In 1945, Roger Sperry showed that it is the location in the brain to which nerves attach that determines experience. He studied amphibians whose optic nerves cross completely, so that the left eye connects to the right side of the brain and the right eye connects to the left side of the brain. He was able to cut the optic nerves and cause them to regrow on the opposite side of the brain so that the left eye now connected to the left side of the brain and the right eye connected to the right side of the brain. He then showed that these animals made the opposite movements from the ones they would have made before the operation. For example, before the operation, the animal would move to the left to get away from a large object approaching from the right. After the operation, the animal would move to the right in response to the same large object approaching from the right. Sperry showed similar results in other animals including mammals (rats), this work contributing to his Nobel Prize in 1981.